<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/8/15
 * Time: 14:46
 */

namespace app\controllers;

use Phalcon\Mvc\View;

class PostsController extends BaseController
{
    public function indexAction()
    {

    }

    public function showAction()
    {
        if ($this->view->getCache()->exists('posts-show')) {
            return $this->view->getCache()->get('posts-show');
        } else {
            $params = $this->request->get('param');
            $this->view->setVar('param', $params);
            $this->view->render('posts', 'show', ['param' => $params]);
            $this->view->cache([
                'key' => 'posts-show'
            ]);
        }
    }
    public function saveAction()
    {
        if ($this->request->isPost() === true) {
             $this->dispatcher->forward([
                'controller' => 'site',
                'action' => 'signin'
            ]);
        } else {
            return $this->flash->error('only support post request');
        }
        return '';
    }

    public function notFoundAction()
    {
        $this->response->setStatusCode(404, 'Not Found');
    }

    public function initialize()
    {
        //关闭渲染
//        $this->view->setRenderLevel(View::LEVEL_NO_RENDER);
        //开启缓存
//        $this->view->cache(true);
    }
}